﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WinForm {
    public partial class FormPwdChange : Form
    {
        
        public FormPwdChange()
        {
            InitializeComponent();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtOldPwd.Text.Trim() != UserHelper.password)
            {
                MessageBox.Show("原始密码错误！");
                txtOldPwd.Focus();
                return;
            }
            if (txtNewPwd.Text.Trim() != txtNewPwdAgain.Text.Trim())
            {
                MessageBox.Show("两次输入的新密码不一致！");
                txtNewPwd.Focus();
                return;
            }
            Model.User model = new Model.User();
            model.UserName = UserHelper.username;
            model.Password = txtNewPwd.Text;
            BLL.User bll = new BLL.User();
            if (bll.Update(model))
            {
                MessageBox.Show("修改密码成功，下次登录请输入新密码。");
                UserHelper.password = txtNewPwd.Text.Trim();
                this.Close();
            }
            else
            {
                MessageBox.Show("密码修改失败！");
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void FormPwdChange_Load(object sender, EventArgs e)
        {
            txtUserName.Text = UserHelper.username;
        }
    }
}
